import { getBanners } from '../../service/api/music'
import queryRect from '../../utils/query-rect'
import throttle from '../../utils/throttle'

//对queryRect查询函数进行节流，减少查询频率
const throttleQueryRect = throttle(queryRect, 1000)

Page({
  data: {
    banners: [],
    swiperHeight: 0
  },
  onLoad() {
    //获取页面数据
    this.getPageData()
  },
  //网络请求
  getPageData() {
    getBanners().then(res => this.setData({ banners: res.banners }))
  },
  handleSearchClick() {
    wx.navigateTo({
      url: '/pages/detail-search/index'
    })
  },
  handleSwiperImageLoaded() {
    //获取图片的高度(如何去获取某一个组件的高度)
    throttleQueryRect('.swiper-image').then(res => this.setData({ swiperHeight: res[0].height }))
  }
});